import React from "react"

import http from "../../helper/request"

const useApi = () => {
	const { useState } = React
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined) {
		setLoading(true)
		const ret = await http.post<T>(url, body)
		setLoading(false)
		return ret
	}
	const paymentChannelConfigList = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentChannelConfig/query", body)
		return ret
	}

	const paymentMerchantConfigStartOrStop = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentMerchantConfig/startOrStop", body)
		return ret
	}
	const updatePaymentChannelConfig = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentChannelConfig/update", body)
		return ret
	}

	const memberWithdrawConfigList = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentChannelConfig/query/withdraw", body)
		return ret
	}
	const updateConfigWithdraw = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentChannelConfig/update/withdraw", body)
		return ret
	}
	const billRelateSettingList = async (body: object | undefined) => {
		const ret = await generalHttp("/report/proxyLoanBill/conf", body)
		return ret
	}
	const updateBillRelateSetting = async (body: object | undefined) => {
		const ret = await generalHttp("/report/proxyLoanBill/conf/set", body)
		return ret
	}

	return {
		billRelateSettingList,
		updateBillRelateSetting,
		updateConfigWithdraw,
		paymentChannelConfigList,
		updatePaymentChannelConfig,
		paymentMerchantConfigStartOrStop,
		memberWithdrawConfigList,
		generalHttp,
		loading
	}
}

export default useApi
